const Controller = require('egg').Controller;
const Error = require('../../class/error');

module.exports = app => {
  return class FrontOperationLogController extends Controller {
    async setArticleLogJson() {
      const ctx = this.ctx;
      const articleId = ctx.query.articleId;
      if (!articleId) {
        ctx.body = Error.UNKOWN;
        return;
      }
      try {
        await this.service.operationLog.create(
          app.config.operationType.type.VIEW,
          app.config.operationType.target.ARTICLE,
          articleId,
          ctx.session.frontUser.user_id
        );
        ctx.body = Error.SUCCESS;
      } catch (e) {
        ctx.body = Error.UNKOWN;
        throw e;
      }

    }

  }
}

